<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 对象
        // var teacher = {
        //     name: '张三',
        //     age: 32,
        //     sex: 'male',
        //     height: 176,
        //     weight: 130,
        //     teach: function(){
        //         console.log('I am teaching Javascript');
        //     },
        //     smoke: function(){
        //         console.log('I am smoking');
        //     },
        //     eat: function(){
        //         console.log('I am having a dinner');
        //     }
        // }

        // console.log(teacher.name);
        // teacher.teach();
        // teacher.address = '北京';
        // console.log(teacher);

        // teacher.drink = function(){
        //     console.log('I am drinking beer');
        // }
        // teacher.drink();

        // delete teacher.address;
        // delete teacher.drink;

        // console.log(teacher);
        

        // 课前热身
        // var attendance = {
        //     student: [],
        //     total: 6,
        //     join: function(name){
        //         this.student.push(name);
        //         if(this.student.length === this.total){
        //             console.log(name + '到课，学生已到齐');
        //         } else{
        //             console.log(name + '到课，学生未到齐');
        //         }
        //     },
        //     leave:function(name){
        //         var idx = this.student.indexOf(name);
        //         if(idx !== -1){
        //             this.student.splice(idx, 1);
        //         }
        //         console.log(name + '早退');
        //         console.log(this.student);
        //     },
        //     classOver: function(){
        //         this.student = [];
        //         console.log('已下课');
        //     }
        // }

        // attendance.join('1');
        // attendance.join('2');
        // attendance.join('3');
        // attendance.join('4');
        // attendance.join('5');
        // attendance.join('6');
        // attendance.leave('1');

        // 自定义构造函数（模块化，插件化，组件化）
        function Teacher(){
            this.name = '张三';
            this.sex = '男士';
            this.weight = 130;
            this.smoke = function(){
                this.weight--;
                console.log(this.weight);
            },
            this.eat = function(){
                this.weight++;
                console.log(this.weight);
            }
        }

        var teacher1 = new Teacher();
        teacher1.smoke();
        teacher1.smoke();
        teacher1.smoke();

        // 作业1
        function NumFn(num1, num2){
            this.num1 = num1;
            this.num2 = num2;
            this.add = function(){
                console.log(this.num1 + '+' + this.num2 + '=' +(this.num1 + this.num2));
            }
            this.cheng = function(){
                console.log(this.num1 + '*' + this.num2 + '=' +(this.num1 * this.num2));
            }
        }

        var numFn = new NumFn(1, 2);
        numFn.add();
        numFn.cheng();

        // 作业2
        function Car(opt){
            this.brand = opt.brand;
            this.color = opt.color;
            this.pailiang = opt.pailiang;
        }
        function Consumer(opt){
            this.name = opt.name;
            this.age = opt.age;
            this.salay = opt.salay;
            this.selCar = function(){
                 var car = new Car(opt.carOpt);
                 console.log(`${this.name}挑选了一辆颜色为${car.color},排量为${car.pailiang}的${car.brand}`);
            }
        }

        var consumer = new Consumer({
            name: '小明',
            age: 24,
            salay: 10000,
            carOpt: {
                brand: '马自达',
                color: '红色',
                pailiang: '2.0'
            }
        })

        consumer.selCar()

    </script>
</body>
</html>